﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyThuVien.DTO;

namespace QuanLyThuVien.DAO
{
    class PhieuThuTienPhatDAO
    {
        public static void PhieuThuTienPhat(PhieuThuTienPhatDTO x)
        {
            NorthwindDataContext QLTV = new NorthwindDataContext();
            PhieuThuTienPhat p = new PhieuThuTienPhat();
            p.SoTienThu = x.SoTienThu1;
            p.ConLai = x.ConLai1;
            p.MaSoGhiNo = x.MaSoGhiNo1;
            p.MaNhanVien = x.MaNhanVien1;
            p.NgayThuTienPhat = x.NgayThuTienPhat1;
            QLTV.PhieuThuTienPhats.InsertOnSubmit(p);
            QLTV.SubmitChanges();
        }

        //lay ra tien no cua cac  doc gia trong ngay
        public static DataTable TienNo_DG(DateTime ngay)
        {
            NorthwindDataContext db = new NorthwindDataContext();
            var ds = from tp in db.PhieuThuTienPhats
                     join sn in db.SoGhiNos on tp.MaSoGhiNo equals sn.MaSoGhiNo
                     join dg in db.DocGias on sn.MaDocGia equals dg.MaDocGia
                     where tp.NgayThuTienPhat.Date == ngay.Date
                     select new
                     {
                         dg.HoTenDocGia,
                         tp.ConLai,
                     };
            DataTable dt = new DataTable();
            dt.Columns.Add("Tên Độc Giả", typeof(string));
            dt.Columns.Add("Tiền Nợ", typeof(float));
            foreach (var gtri in ds)
            {
                dt.Rows.Add(gtri.HoTenDocGia, gtri.ConLai);
            }
            return dt;
        }
    }
}
